package com.ysx.oa.role.controller;


import com.ysx.oa.role.bean.RoleBean;
import com.ysx.oa.role.bean.RoleUserBean;
import com.ysx.oa.role.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {


    @Autowired
    private RoleService service;

    // http://localhost:8080/kaoqin/role/find.do?id=800200
    @RequestMapping(value="/find.do",method = RequestMethod.GET)
    public Map<String,Object> findById(Integer id){
        Map<String,Object> map = new HashMap();

        RoleBean bean=null;
        try{
            bean = service.findById(id);
        }catch (Exception exception){
            System.out.println(exception);
        }

        map.put("code",200);
        map.put("message","success");
        map.put("data",bean);
        return map;
    }

    @RequestMapping(value = "/add.do",method = RequestMethod.POST)
    public Map<String,Object> add(@RequestBody RoleBean bean){
        Map<String,Object> map = new HashMap();
        service.add(bean);

        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }
    @RequestMapping(value = "/sum.do",method = RequestMethod.GET)
    public Map<String,Object> sum(Integer x, Integer y){
        Map<String,Object> map = new HashMap();
        int sum = service.sum(x,y);

        map.put("code",200);
        map.put("message","success");
        map.put("data",sum);
        return map;
    }

    // http://localhost:8080/kaoqin/role/find.do?id=800200
    /*@RequestMapping(value="/findAll.do",method = RequestMethod.GET)
    public Map<String,Object> findAllRole(){
        Map<String,Object> map = new HashMap();
        Integer userId=10010;

        List<RoleUserBean> data=null;
        try{
            data = service.findAllRole(userId);
        }catch (Exception exception){
            System.out.println(exception);
        }

        map.put("code",200);
        map.put("message","success");
        map.put("data",data);
        return map;
    }*/

}
